/*
 * TCSS 422 Web Spider Project
 * Group Money: Al McKenzie, Michael Pitts, Taylor Zielske
 */
package model.domain;

import java.net.MalformedURLException;

import model.URLInputCooker;

/**
 * This class provides the basic functionality that all Domains will share.
 * 
 * @author Michael Pitts
 * @version Oct 18, 2011
 */
public abstract class AbstractDomain implements Domain {

	/**
	 * The string representation of the domain.
	 */
	private final String my_domain;
	
	/**
	 * Stores the URLInputCooker that will be used to set-up url input buffers.
	 */
	private final URLInputCooker my_cooker;
	
	/**
	 * Creates a new Domain.
	 * @param the_domain is the string representation of the new domain.
	 * @param the_cooker is the URLInputCooker for this program.
	 */
	public AbstractDomain(final String the_domain, final URLInputCooker the_cooker) {
		my_domain = the_domain;
		my_cooker = the_cooker;
	}
	
	/**
	 * Adds the given url to the URLInputCooker so it can eventually be parsed.
	 * @param the_url is the url to add to the cooker.
	 */
	protected final void addURLToCooker(final String the_url) {
		my_cooker.addURL(the_url);
	}
	
	/**
	 * Adds the given domain's robots.txt url to the cooker so it can be parsed for
	 * the domain spider rules.
	 * @param the_domain is the domain to be tested.
	 * @throws MalformedURLException if the given url can not be parsed.
	 */
	protected final void cookDomain(final String the_domain) throws MalformedURLException {
		my_cooker.addDomain("http://" + the_domain + "/robots.txt");
	}

	/**
	 * {@inheritDoc}
	 */
	@Override public abstract void addURL(final String the_url);

	/**
	 * {@inheritDoc}
	 */
	@Override public String getDomain() {
		return my_domain;
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override public int hashCode() {
		return my_domain.hashCode();
	}
}
